from datetime import datetime

from pydantic import Field
from typing import Optional, Annotated, List

from ...base import BaseApiListOut, BaseSchema, BaseApiOut


class BrandUserBase(BaseSchema):
    code: Optional[str] = Field(None, description='商户编码')
    brand_id: Optional[int] = Field(None, description='品牌编码')
    name: Optional[str] = Field(None, description='显示名称')
    email: Optional[str] = Field(None, description='Email')
    username: Optional[str] = Field(None, description='用户名')
    type: Optional[int] = Field(None, description='状态 1商户号 2子账户')
    is_active: Optional[int] = Field(None, description='状态 0禁用 1启用')


class BrandUserCreate(BrandUserBase):
    is_setpass: Optional[int] = Field(None, description='设置密码 0不操作 1设置密码')
    password: Optional[str] = Field(None, description='密码')
    comfirm_password: Optional[str] = Field(None, description='密码')


class BrandUser(BrandUserBase):
    id: Optional[int] = Field(0, description='自增ID')

    role_id: Optional[int] = Field(None, description='角色 ID')
    admin_id: Optional[int] = Field(None, description='添加人')

    last_login_ip: Optional[str] = Field(None, description='最后登录 IP')
    last_login_at: Optional[datetime] = Field(None, description='最后登录时间')

    created_at: Annotated[Optional[datetime], Optional[str]] = None
    updated_at: Annotated[Optional[datetime], Optional[str]] = None


class BrandUserOut(BaseApiOut):
    data: Annotated[BrandUser, None] = None


class BrandUserListOut(BaseApiListOut):
    data: Annotated[List[BrandUser], None] = None
